%> @file cc_mpc_coldstart_contraintsevaluation.m
%> @brief The function evaluates the constraints matrices for the constrained MPC/RHC control.
%> 
%> @author Mikhail Konnik
%> @date   12 January 2012
%>
%> @section mpccoldstart Cold Start of the MPC controller
%> The problem is typically formulated as a Quadratic Programming (QP) consisting of minimising the cost function~\eqref{eq:costfunctionmpcHessian}. In this paper we consider linear constraints for the control inputs:
%> 
%> \f$  M \cdot U \leq \eta, \mbox{ where } M = \left[ \begin{array}{c} I_{(N_c+1) \cdot m} \\ - I_{(N_c+1) \cdot m} \\ \end{array} \right] \mbox{ and } \eta = \left[\begin{array}{c}\mathbf{u}_{max} \\\mathbf{u}_{min} \\\end{array}\right], \f$
%> 
%> where \f$I_{(N_c+1) \cdot m}\f$ is the \f$(N_c+1) \cdot m\times (N_c+1) \cdot m\f$ identity matrix, \f$N_c\f$ is the control prediction horizon, and \f$m\f$ is the number of inputs. The matrix \f$\mathbf{u}_{max} = [u_{max,0}, u_{max,1}, \dots u_{max,N_c}]\f$ contains the maximum allowable   inputs and the matrix \f$\mathbf{u}_{min} = [- u_{min,0}, - u_{min,1}, \dots - u_{min,N_c}]\f$ contains the minimum allowable   inputs. The \textit{constrained solution} for the RHC problem is then found by solving a QP \textit{at each sample instant} of the form:
%> 
%> \f$ \operatorname*{min}_{U} \,\,\,\, \frac{1}{2} U^T \mathbb{H} U +  U^T \mathbb{F} x   ,\,\,\,\,\,\,  \mbox{subject to :    }  M \cdot U \leq \eta \f$
%> 
%> where \f$U\f$ is a vector of future inputs. In the case when the Hessian matrix \f$\mathbb{H}\f$ is positive definite, which is the usually true for the adaptive optics, the quadratic optimisation problem is convex and therefore the constrained solution   exists and is unique.
%======================================================================
%> @param Nc		= control prediction horizon.
%> @param u_max		= maximum constraint value.
%> @param u_min			= minimal constraint value.
%> @param col_B_e			= number of inputs in the plant.
%> @retval gamma			= discrete state evolution matrix A.
%> @retval M			= discrete input matrix B.
% ======================================================================
function [gamma, M] = cc_mpc_coldstart_contraintsevaluation(Nc,u_max,u_min,col_B_e)


%%%%%%%%% START: Contraints on Control amplitude u
Constraints_number=Nc;  %% This way, it will work with MIMO, but at the cost of all constraints.


%%%%%%%%%% ### START: Augmentation of the Control Amplitude Constrains for the MIMO case.
gamma_max = [];
	for jj=1:Constraints_number;
	gamma_max = [gamma_max; u_max];
	end

gamma_min = [];
	for jj=1:Constraints_number;
	gamma_min = [gamma_min; u_min];
	end
gamma = [gamma_max; -gamma_min];
%%%%%%%%%% ### END: Augmentation of the Control Amplitude Constrains for the MIMO case.


%%%%% This here is the exact implementation of the De Dona book. Nc is important here - this means that the control signals will be ALL constrainted!
M0 = speye(Nc*col_B_e);
M=[M0;-M0];
%%%%% This here is the exact implementation of the De Dona book

%%%%%%%%% END: Contraints on Control amplitude u

